package cn.com.lms.business.questionnaire.persistence.entity;

import cn.com.lms.business.learning.persistence.entity.FbLearningStageDetail;
import com.bnzj.core.json.DateDeserializer;
import com.bnzj.core.persistence.entity.BaseEntity;
import com.bnzj.core.util.FbConstant;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @Author: 16266
 * @DateTime: 2020/3/20 14:12
 * @Description: 问卷信息实体
 */
@Entity
@Getter
@Setter
@ToString(callSuper = true)
@Table(name = "bnz_questionnaire_info", schema = "bnzj")
public class QuestionnaireInfo extends BaseEntity {

    private static final long serialVersionUID = -4627332927848244427L;

    @Schema(description = "问卷名称")
    private String questionnaireName;

    @Schema(description = "问卷描述")
    private String questionnaireDesc;

    @Schema(description = "状态：0：待发布，1：进行中，2：已结束")
    private Byte status;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = FbConstant.DATETIME_FORMAT)
    @JsonDeserialize(using = DateDeserializer.class)
    @JsonFormat(pattern = FbConstant.DATETIME_FORMAT, timezone = "GMT+8")
    @Schema(description = "开始时间")
    private Date startTime;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = FbConstant.DATETIME_FORMAT)
    @JsonDeserialize(using = DateDeserializer.class)
    @JsonFormat(pattern = FbConstant.DATETIME_FORMAT, timezone = "GMT+8")
    @Schema(description = "结束时间")
    private Date endTime;

    @Schema(description = "是否删除 0：未删除，1：已删除")
    private Boolean isDelete;

    @Schema(description = "问卷题目")
    @OneToMany(targetEntity = QuestionnaireSub.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "questionnaireInfoId", referencedColumnName = "id")
    private List<QuestionnaireSub> questionnaireSubList;

    @OneToMany(targetEntity = FbLearningStageDetail.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "obj_id", referencedColumnName = "id")
    @Where(clause = "study_type = 1")
    private List<FbLearningStageDetail> fbLearningStageDetailList;


}
